<template>
  <div class>
    <div class="outmain ba_f">
      <div class="shuju_title mar_b20">
        <div class="shuju_title_text">
          <span>服务费率</span>
        </div>
      </div>
      <el-form ref="form" :model="form" label-width="180px" class="mar_t20">
        <el-form-item label="抽佣规则">
          <el-radio-group v-model="form.rule">
            <el-radio label="1">统一比例</el-radio>
            <el-radio label="2">按商家分组</el-radio>
            <el-radio label="3">按区域</el-radio>
            <!-- <el-radio label="4">门店单独设置</el-radio> -->
          </el-radio-group>
        </el-form-item>

        <div v-if="form.rule=='1'">
<!--          <el-form-item label="结算周期">-->
<!--            <el-input v-model.trim="form.day" autocomplete="off" placeholder="请输入结算周期">-->
<!--              <template slot="append">天</template>-->
<!--            </el-input>-->
<!--          </el-form-item>-->
          <el-form-item label="佣金计算方式">
            <el-radio-group v-model="form.type">
              <el-radio label="1">按订单百分比抽成</el-radio>
              <el-radio label="2">按固定金额</el-radio>
            </el-radio-group>
          </el-form-item>
          <div v-if="form.type=='1'">
            <el-form-item label="商品抽佣比例">
              <el-input v-model="form.goodsPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <!--                                        <el-input v-model="form.name" style="width: 220px">-->
              <!--                                            <template slot="prepend">区域抽佣</template>-->
              <!--                                            <template slot="append">%</template>-->
              <!--                                        </el-input>-->
              <el-input v-model="form.goodsStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.goodsDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="配送费抽佣比例">
              <el-input v-model="form.deliverPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">%</template>-->
              <!--                                    </el-input>-->
              <el-input v-model="form.deliverStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.deliverDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="包装费抽佣比例">
              <el-input v-model="form.boxPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">%</template>-->
              <!--                                    </el-input>-->
              <el-input v-model="form.boxStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.boxDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="当面付抽佣比例">
              <el-input v-model="form.cashierPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <el-input v-model="form.cashierStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.cashierDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="快餐抽佣比例">
              <el-input v-model="form.fastPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <el-input v-model="form.fastStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.fastDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="店内抽佣比例">
              <el-input v-model="form.inStorePlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <el-input v-model="form.inStoreStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.inStoreDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </div>
          <div v-if="form.type=='2'">
            <el-form-item label="商品抽成金额">
              <el-input v-model="form.goodsFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">元</template>-->
              <!--                                    </el-input>-->
            </el-form-item>
            <el-form-item label="配送费抽成金额">
              <el-input v-model="form.deliverFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">元</template>-->
              <!--                                    </el-input>-->
            </el-form-item>
            <el-form-item label="包装费抽成金额">
              <el-input v-model="form.boxFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">元</template>-->
              <!--                                    </el-input>-->
            </el-form-item>
            <el-form-item label="当面付抽成金额">
              <el-input v-model="form.cashierFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="快餐抽成金额">
              <el-input v-model="form.fastFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="店内抽成金额">
              <el-input v-model="form.inStoreFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
    <div class="mar_t20 ba_f pad_20 t_c">
      <el-button type="primary" @click="submitForm">保存</el-button>
    </div>
  </div>
</template>
<script>
import { getConfig, postConfig } from '@/api/setup';
export default {
  created() {
    this.init();
  },
  data() {
    return {
      form: {
        rule: '1',
        type: '2',
        day: '',
        goodsPlatformProportion: 0,
        goodsStoreProportion: 100,
        goodsDownMoney: 0,
        deliverPlatformProportion: 0,
        deliverStoreProportion: 100,
        deliverDownMoney: 0,
        boxPlatformProportion: 0,
        boxStoreProportion: 100,
        boxDownMoney: 0,
        goodsFixedMoney: 0,
        deliverFixedMoney: 0,
        boxFixedMoney: 0,
        cashierPlatformProportion: 0,
        cashierStoreProportion: 100,
        cashierDownMoney: 0,
        cashierFixedMoney: 0,
        fastPlatformProportion: 0,
        fastStoreProportion: 100,
        fastDownMoney: 0,
        fastFixedMoney: 0,
        inStorePlatformProportion: 0,
        inStoreStoreProportion: 100,
        inStoreDownMoney: 0,
        inStoreFixedMoney: 0
      }
    };
  },
  methods: {
    async init() {
      const { data } = await getConfig({ ident: 'serviceCharge' });
      this.form2 = this.form;
      this.form = Object.assign(this.form2, data);
      this.form.goodsStoreProportion = 100 - this.form.goodsPlatformProportion;
      this.form.deliverStoreProportion = 100 - this.form.deliverPlatformProportion;
      this.form.boxStoreProportion = 100 - this.form.boxPlatformProportion;
      this.form.cashierStoreProportion = 100 - this.form.cashierPlatformProportion;
      this.form.fastStoreProportion = 100 - this.form.fastPlatformProportion;
      this.form.inStoreStoreProportion = 100 - this.form.inStorePlatformProportion;
    },
    submitForm() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          this.form.ident = 'serviceCharge';
          const { msg } = await postConfig(this.form);
          this.$baseMessage(msg, 'success');
          this.init();
        } else {
          return false;
        }
      });
    }
  }
};
</script>
